local zhuoqu = fk.CreateSkill {
  name = "inker_zhuoqu",
}

Fk:addQmlMark{
  name = "inker_card_ids",
  how_to_show = function() return " " end,
  qml_data = function(name, value, player)
    if type(value) ~= "table" then return {} end
    local ret = {}
    for _, num in ipairs(value) do
      table.insert(ret, Fk:cloneCard("ex_nihilo", Card.Heart, num))
    end
    return ret
  end,
  qml_path = "packages/utility/qml/ListMarkBox",
}

zhuoqu:addEffect("viewas", {
  anim_type = "drawcard",
  pattern = "ex_nihilo",
  mute_card = false,
  prompt = "#inker_zhuoqu",
  filter_pattern = {
    max_num = 1,
    min_num = 1,
    pattern = ".|1~13"
  },
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("ex_nihilo")
    c:addSubcards(cards)
    c.skillName = zhuoqu.name
    return c
  end,
})
zhuoqu:addEffect(fk.PreCardUse, {
  mute = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card and table.contains(data.card.skillNames, zhuoqu.name) and data.card.number > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:addTableMarkIfNeed(player, "@[inker_card_ids]inker_zhuoqu", data.card.number)
  end,
})
zhuoqu:addEffect(fk.AfterCardsMove, {
  mute = true,
  can_refresh = function(self, event, target, player, data)
    if player.phase == Player.Discard then return end
    local mark = player:getTableMark("@[inker_card_ids]inker_zhuoqu")
    if #mark == 0 then return end
    for _, move in ipairs(data) do
      if move.from == player and move.moveReason == fk.ReasonDiscard then
        return true
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getTableMark("@[inker_card_ids]inker_zhuoqu")
    if #mark == 0 then return end
    for _, move in ipairs(data) do
      if move.from == player and move.moveReason == fk.ReasonDiscard then
        for _, info in ipairs(move.moveInfo) do
          local c = Fk:getCardById(info.cardId)
          if c and c.number > 0 then
            table.removeOne(mark, c.number)
          end
        end
      end
    end
    player.room:setPlayerMark(player, "@[inker_card_ids]inker_zhuoqu", #mark > 0 and mark or 0)
  end
})
local prohibit_func = function(self, player, card)
    local mark = player:getTableMark("@[inker_card_ids]inker_zhuoqu")
    for _, cid in ipairs(Card:getIdList(card)) do
      local c = Fk:getCardById(cid)
      if c and c.number > 0 and table.contains(mark, c.number) then
        return true
      end
    end
  end
zhuoqu:addEffect("prohibit", {
  prohibit_use = prohibit_func,
  prohibit_response = prohibit_func,
})

Fk:loadTranslationTable{
  ["inker_zhuoqu"] = "灼躯",
  [":inker_zhuoqu"] = "你可将一张牌当作【无中生有】使用，直至你于弃牌阶段外弃置同点数牌前无法使用或打出同点数牌。",

  ["#inker_zhuoqu"] = "灼躯：将一张牌当作【无中生有】使用，直至你于弃牌阶段外弃置同点数牌前无法使用或打出同点数牌",

  ["@[inker_card_ids]inker_zhuoqu"] = "灼躯",
}

return zhuoqu